package com.lagou.edu.ad.controller;

import com.lagou.edu.common.result.ResponseDTO;
import com.lagou.edu.ad.api.AdRemoteService;
import com.lagou.edu.ad.api.dto.PromotionAdDTO;
import com.lagou.edu.ad.api.dto.PromotionSpaceDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @author lm
 * @since 2021/10/13 15:38
 */
@Api(tags = "广告接口", produces = "application/json")
@RestController
@RequestMapping("/ad")
public class AdController {
    @Autowired
    private AdRemoteService adRemoteService;

    @ApiOperation("根据ID获取广告位")
    @GetMapping("/space/getSpaceById")
    public ResponseDTO<PromotionSpaceDTO> getSpaceById(@RequestParam(name = "id") Integer id) {
        return ResponseDTO.success(adRemoteService.getSpaceById(id));
    }

    @ApiOperation(value = "获取所有的广告位")
    @GetMapping("/space/getAllSpaces")
    public ResponseDTO<List<PromotionSpaceDTO>> getAllSpaces() {
        return ResponseDTO.success(adRemoteService.getAllSpaces());
    }

    @ApiOperation("获取广告位及其广告")
    @GetMapping("/space/getSpaceAndAd")
    public ResponseDTO<List<PromotionSpaceDTO>> getSpaceAndAd(@RequestParam(name = "spaceKeys") String[] spaceKeys) {
        return ResponseDTO.success(adRemoteService.getSpaceAndAd(spaceKeys));
    }

    @ApiOperation(value = "保存或更新广告位")
    @PostMapping("/space/saveOrUpdateSpace")
    public ResponseDTO<Boolean> saveOrUpdateSpace(@RequestBody PromotionSpaceDTO promotionSpaceDTO) {
        return ResponseDTO.success(adRemoteService.saveOrUpdateSpace(promotionSpaceDTO));
    }

    @ApiOperation("根据ID获取广告")
    @GetMapping("/getAdById")
    public ResponseDTO<PromotionAdDTO> getAdById(@RequestParam(name = "id") Integer id) {
        return ResponseDTO.success(adRemoteService.getAdById(id));
    }

    @ApiOperation("获取所有广告列表")
    @GetMapping("/getAdList")
    public ResponseDTO<List<PromotionAdDTO>> getAdList() {
        return ResponseDTO.success(adRemoteService.getAdList());
    }

    @ApiOperation("新增或更新广告")
    @PostMapping("/saveOrUpdateAd")
    public ResponseDTO<Boolean> saveOrUpdateAd(@RequestBody PromotionAdDTO promotionAdDTO) {
        return ResponseDTO.success(adRemoteService.saveOrUpdateAd(promotionAdDTO));
    }

    @ApiOperation("更新广告状态")
    @GetMapping("/updateStatus")
    public ResponseDTO<Boolean> updateStatus(@RequestParam(name = "id") Integer id, @RequestParam(name = "status") Integer status) {
        return ResponseDTO.success(adRemoteService.updateStatus(id, status));
    }
}
